﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using AjaxControlToolkit;

public partial class Main_Shop : System.Web.UI.Page
{
    EncriptManager em = new EncriptManager();
    ShopDao sd = new ShopDao();
    DataTable dt = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            SetPageData("1",dlcy);
            SetPageData("2", dlxx);
            SetPageData("3", dlgw);
            SetPageData("4", dlsh);
            dt = sd.getField();
            ddlfield.DataSource = dt;
            ddlfield.DataTextField = "Fname";
            ddlfield.DataValueField = "Fid";
            ddlfield.DataBind();
        }
    }

    private void SetPageData(string fid,DataList dl)
    {
        dt = sd.getShop(fid,"0","","8");
        dl.DataSource = dt;
        dl.DataBind();
        if (dt != null)
        {
            for (int i = 0; i < dl.Items.Count; i++)
            {
                Rating ThaiRating = dl.Items[i].FindControl("ThaiRating") as Rating;
                int hot = Convert.ToInt32(dt.Rows[i][11]);
                ThaiRating.MaxRating = hot;
                ThaiRating.CurrentRating = hot;
                HiddenField Hiddensid = dl.Items[i].FindControl("Hiddensid") as HiddenField;
                HyperLink Hlkshop = dl.Items[i].FindControl("Hlkshop") as HyperLink;
                ImageButton Imbtnimage = dl.Items[i].FindControl("Imbtnimage") as ImageButton;
                string sid = em.Encript(Hiddensid.Value);
                Hlkshop.NavigateUrl = "ShopInfo.aspx?sid=" + sid;
                Imbtnimage.PostBackUrl = "ShopInfo.aspx?sid=" + sid;
            }
        }
    }
    protected void btnsearch_Click(object sender, EventArgs e)
    {
        dt = sd.getShop(ddlfield.SelectedValue, ddltype.SelectedValue.Replace("--请选择--", "0"), txtname.Text, "0");
        if (dt == null)
        {
            string script = "<script>window.alert('对不起，没有相关店面信息！');</script>";
            Page.RegisterClientScriptBlock("", script);
            return;
        }
        if (dt.Rows.Count == 0)
        {
            string script = "<script>window.alert('对不起，没有相关店面信息！');</script>";
            Page.RegisterClientScriptBlock("", script);
            return;
        }
        dlshop.DataSource = dt;
        dlshop.DataBind();
        if (dt != null)
        {
            for (int i = 0; i < dlshop.Items.Count; i++)
            {
                Rating ThaiRating = dlshop.Items[i].FindControl("ThaiRating") as Rating;
                int hot = Convert.ToInt32(dt.Rows[i][11]);
                ThaiRating.MaxRating = hot;
                ThaiRating.CurrentRating = hot;
                HiddenField Hiddensid = dlshop.Items[i].FindControl("Hiddensid") as HiddenField;
                HyperLink Hlkshop = dlshop.Items[i].FindControl("Hlkshop") as HyperLink;
                ImageButton Imbtnimage = dlshop.Items[i].FindControl("Imbtnimage") as ImageButton;
                string sid = em.Encript(Hiddensid.Value);
                Hlkshop.NavigateUrl = "ShopInfo.aspx?sid=" + sid;
                Imbtnimage.PostBackUrl = "ShopInfo.aspx?sid=" + sid;
            }
        }
        Panel1.Visible = true;
        Panel2.Visible = false;
    }
    protected void ddlfield_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddltype.Items.Clear();
        ddltype.Items.Add("--请选择--");
        dt = sd.getType(ddlfield.SelectedValue);
        ddltype.DataSource = dt;
        ddltype.DataTextField = "Tname";
        ddltype.DataValueField = "Tid";
        ddltype.DataBind();
        txtname.Text = "";
    }
}
